package cate.game.role.res.guild.msg.basic;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.chat.ChatRequest;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdGuild;
import cate.game.role.Role;
import cp.solution.business.sys.env.EnvironmentVarSets;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "重置公会名称的请求")
@OperationSetter(value = GDOperation.GUILD_RENAME)
public class ResetNameReq implements MsgInput {
    @NoteField(value = "新的公会名")
    public String guildName;

    @NoteField(value = "公会名内容验证")
    public String checkSign;

    @Override
    public MsgConfig conf() {
        return MsgIdGuild.RESET_NAME_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        h(game, cc.getRole());
    }

    public void h(GameBody game, Role role) {
        if(EnvironmentVarSets.getInstance().isRenameDisabled()) {
            game.notice.message(role, EnvironmentVarSets.getInstance().getRenameDisabledAlert());
        }
        perform(game, role, () -> {
            if (!role.getRes().guild.checkGuild().ok()) {
                game.notice.message(role ,310450,"尚未加入公会");
                return;
            }
            ChatRequest.checkSign(this.guildName, checkSign);
            role.getRes().guild.getGuild().basic.changeGuildName(role, guildName);
        });
    }
}
